//
// Created by 吴锐 on 2022/3/3.
//

#include "iostream"
#include "vector"
#include "algorithm"

using namespace std;

class Greater20 {
public:
    bool operator()(int val) {
        return val > 20;
    }
};

void test01() {
    vector<int> v;
    v.push_back(10);
    v.push_back(40);
    v.push_back(30);
    v.push_back(20);
    v.push_back(40);
    v.push_back(20);

    int num = count_if(v.begin(), v.end(), Greater20());

    cout << "大于20的元素个数有" << num << "个";
}

class Person {
public:
    string name;
    int age;

    Person(string naem, int age) {
        this->name = naem;
        this->age = age;
    }
};

class AgeGreater20 {
public:
    bool operator()(const Person &p) {
        return p.age > 20;
    }
};

void test02() {
    vector<Person> v;

    Person p1("aaa", 15);
    Person p2("bbb", 15);
    Person p3("ccc", 15);
    Person p4("ddd", 45);
    Person p5("eee", 25);
    Person p6("fff", 35);

    v.push_back(p1);
    v.push_back(p2);
    v.push_back(p3);
    v.push_back(p4);
    v.push_back(p5);
    v.push_back(p6);

    int num = count_if(v.begin(), v.end(), AgeGreater20());

    cout << "年龄大于20岁的人有" << num << "个" << endl;
}

int main() {
//    test01();
    test02();
    return 0;
}